<a href="http://github.com/angular/angular.js/tree/v1.2.10/src/auto/injector.js#L3" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/auto/injector.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">angular.injector</code>
<div><span class="hint">API in module <code ng:non-bindable="">ng</code>
</span>
</div>
</h1>
<div><h2 id="description">Description</h2>
<div class="description"><div class="angular-injector-page"><p>Creates an injector function that can be used for retrieving services as well as for
dependency injection (see <a href="guide/di">dependency injection</a>).</p>
</div></div>
<h2 id="usage">Usage</h2>
<div class="usage"><pre class="prettyprint linenums">angular.injector(modules);</pre>
<h4 id="usage_parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>modules</td><td><a href="" class="label type-hint type-hint-array">Array.&lt;string|Function&gt;</a></td><td><div class="angular-injector-page"><p>A list of module functions or their aliases. See
<a href="api/angular.module"><code>angular.module</code></a>. The <code>ng</code> module must be explicitly added.</p>
</div></td></tr></tbody></table><h4 id="usage_returns">Returns</h4><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-function">function()</a></td><td><div class="angular-injector-page"><p>Injector function. See <a href="api/AUTO.$injector"><code>$injector</code></a>.</p>
</div></td></tr></table></div>
<h2 id="example">Example</h2>
<div class="example"><div class="angular-injector-page"><p>Typical usage
<pre class="prettyprint linenums">
  // create an injector
  var $injector = angular.injector(['ng']);

  // use the injector to kick off your application
  // use the type inference to auto inject arguments, or use implicit injection
  $injector.invoke(function($rootScope, $compile, $document){
    $compile($document)($rootScope);
    $rootScope.$digest();
  });
</pre>
<p>Sometimes you want to get access to the injector of a currently running Angular app
from outside Angular. Perhaps, you want to inject and compile some markup after the
application has been bootstrapped. You can do this using extra <code>injector()</code> added
to JQuery/jqLite elements. See <a href="api/angular.element"><code>angular.element</code></a>.</p>
<p><em>This is fairly rare but could be the case if a third party library is injecting the
markup.</em></p>
<p>In the following example a new block of HTML containing a <code>ng-controller</code>
directive is added to the end of the document body by JQuery. We then compile and link
it into the current AngularJS scope.</p>
<pre class="prettyprint linenums">
var $div = $('&lt;div ng-controller="MyCtrl"&gt;{{content.label}}&lt;/div&gt;');
$(document.body).append($div);

angular.element(document).injector().invoke(function($compile) {
  var scope = angular.element($div).scope();
  $compile($div)(scope);
});
</pre>
</div></div>
</div>
